package org.jeecg.modules.flow.callback.move;

import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.transfer.entity.WmsMoveReceipt;
import org.jeecg.modules.business.transfer.service.IWmsMoveReceiptService;
import org.jeecg.modules.business.transfer.vo.WmsMoveReceiptPage;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    移库保存
 * 创建人员:    lumingyi
 * 创建时间:    2023-09-25
 */
@Component
public class MoveReceiptSaveBean<T> extends BaseCustomBeanRun<T> {

    @Autowired
    private IWmsMoveReceiptService wmsMoveReceiptService;

    @Override
    public void actureRun() {
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        // 转class.自定义class,data对应的class
        baseFlowDto.translateClass(WmsMoveReceiptPage.class);
        WmsMoveReceiptPage wmsMoveReceiptPage = (WmsMoveReceiptPage)baseFlowDto.getData();

        WmsMoveReceipt wmsMoveReceipt = new WmsMoveReceipt();
        BeanUtils.copyProperties(wmsMoveReceiptPage, wmsMoveReceipt);
        if (StringUtils.isBlank(wmsMoveReceiptPage.getId())) {
            wmsMoveReceiptService.saveMain(wmsMoveReceipt, wmsMoveReceiptPage.getWmsMoveReceiptMaterialList());
        } else {
            wmsMoveReceiptService.updateMain(wmsMoveReceipt, wmsMoveReceiptPage.getWmsMoveReceiptMaterialList());
        }
        baseFlowDto.setInfoId(wmsMoveReceipt.getId());
        baseFlowDto.setResult(Result.OK());
    }
}
